<?php

if (!isset($_SESSION))
    session_start();
require_once("dbclass.php");

class ItineraryDBclass {

    public $db;
    public $error = "&nbsp;";
    private $booking_data = array("idUser" => "", "itineraryId" => "", "bookingDate" => "", "email" => "", "location" => "", "guestsCount" => 0);

    public function SetData($idUser, $itineraryId, $bookingDate, $email, $location, $guestsCount) {
        $this->booking_data["idUser"] = $idUser;
        $this->booking_data["itineraryId"] = $itineraryId;
        $this->booking_data["bookingDate"] = $bookingDate;
        $this->booking_data["email"] = $email;
        $this->booking_data["location"] = $location;
        $this->booking_data["guestsCount"] = $guestsCount;
    }

    public function connectToDb() {
        $this->db = new dbclass;
        $parameters = array("localhost:3306","root","expedia");
        $this->db->connect($parameters)->select_db("eandb");
    }

    public function insertData() {
        if ($this->booking_data["idUser"] != "" && $this->booking_data["itineraryId"] != "") {

            $result = $this->db->query("INSERT INTO bookings SET idUser = '" . $this->booking_data["idUser"] . "',
                                                              itineraryId = '" . $this->booking_data["itineraryId"] . "',
                                                              bookingDate = '" . $this->booking_data["bookingDate"] . "',
                                                              email = '" . $this->booking_data["email"] . "',
                                                              location  = '" .$this->booking_data["location"] ."',
                                                              guestsCount = " . $this->booking_data["guestsCount"]                                  
                    );
        }
    }

    public function getBookings($username) {
        $result = $this->db->query("SELECT bookings.email, bookings.itineraryId, bookings.location, bookings.guestsCount, bookings.bookingDate FROM users INNER JOIN bookings ON users.id = bookings.idUser where username='$username'")->fetch();
        return $result;
    }

    public function GetIdUser($username) {
        echo $username;
        $result = $this->db->query("SELECT id FROM users where username='$username'")->fetch();
        //print_r($result);
        return $result[0]['id'];
    }

}

?>
